<?php

namespace pmvc\mvc\view;

use pmvc\Properties;

/**
 * Convenience class for retrieving property values from one or more Properties objects.
 * 
 * Properties objects are given preference from most recently added to least recently added.
 */
class PropertiesLookup {
	
	private $propertiesObjs = Array();

	public function add(Properties $propertiesObj) {
		array_splice($this->propertiesObjs, 0, 0, Array($propertiesObj));
	}
	
	public function addAll(array $propertiesObjs) {
		array_splice($this->propertiesObjs, 0, 0, array_reverse($propertiesObjs));
	}
	
	public function getProperty($name, $default=NULL) {
		foreach ($this->propertiesObjs as $propertiesObj) {
			if ($propertiesObj->hasProperty($name)) {
				return $propertiesObj->getProperty($name, $default);
			}
		}
		return $default;
	}
}

?>